/**
 * Created by hanj on 2022/3/19 13:52
 */
package com.example.demo;

import com.example.demo.entity.Parent;
import com.example.demo.entity.Teacher;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * 线程 3
 *
 *
 */
public class Thread3 implements Runnable {

    //通过上下文实现bean注入

    //线程计数器
    private CountDownLatch latch;

    public Thread3() {
    }

    public Thread3(CountDownLatch latch) {
        this.latch = latch;
    }

    @Override
    public void run() {
        try {
            System.out.println(Thread.currentThread().getName() + "future3启动中。。。。。。");
            List<Parent> data = getData();
            System.out.println(Thread.currentThread().getName() + "future3打印：" + data);


        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            latch.countDown();
            System.out.println(Thread.currentThread().getName() + "latch数量：" + latch.getCount());
        }
    }

    //模拟导出数据
    private List<Parent> getData() {
        List<Parent> result = new ArrayList<>();
        Parent parent = new Parent();
        parent.setName("张三");
        parent.setSex("男");
        parent.setCall("父亲");
        result.add(parent);

        Parent parent1 = new Parent();
        parent1.setName("李四");
        parent1.setSex("女");
        parent1.setCall("母亲");
        result.add(parent1);
        return result;
    }
}
